package com.config;

import java.lang.reflect.Field;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

/**
 * 配置信息
 * @author luanzhe
 * @since 2005-9-24
 * @version 1.0
 * @see
 */
public  class CONFIG{
	public static String SHOW_FILE_PATH = "";
	public static String NEWS_FILE_PATH = "";
	public static String FILE_BUFFER_PATH = "";
	Logger logger = Logger.getLogger(CONFIG.class);
    private static CONFIG config = null;
    
    /** 每页显示记录数 */
	public static int ITEM_COUNT_PER_PAGE = 15;
	/**文件的绝对路径*/
	public static String BASE_FILE_PATH = "";
	/**文件的下载路径*/
	public static String BASE_DOWN_PATH = "";
	
	static{
		
	}
	private CONFIG()
	{
		logger.info("construct CONFIG and init.....");
	    initParameter();
	}
	/**
	 * 取得CONFIG实例
	 * @return CONFIG
	 *
	 */
	public static CONFIG getInstance()
	{
	    if(config == null)
	    {
	        config = new CONFIG();
	    }
	    return config;
	    
	}
	/**
	 * 从config.properties中取得系统的配置信息
	 *  void
	 *
	 */
	private void initParameter()
	{
		ResourceBundle bundle = ResourceBundle.getBundle("config.config");
		
		Field[] field = getClass().getFields();
		for(int i=0;i<field.length;i++){
			if("SYSTEMS".equals(field[i].getName()))continue;
    		if("int".equals(field[i].getType().getName())){
    			int value = 10;
    		try{
    			value = Integer.parseInt(bundle.getString(field[i].getName()));
	    		} catch (NumberFormatException e) {
					value = 10;
				}
    			try {
    			
    				//System.out.println(value);
					field[i].setInt(config,value);
    			}
				 catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				}
    		}else{
    			try {
    				Object value = bundle.getString(field[i].getName());
        			//System.out.println(value);
    					field[i].set(config,value);
        			}
    				 catch (IllegalArgumentException e) {
    					e.printStackTrace();
    				} catch (IllegalAccessException e) {
    					e.printStackTrace();
    				}
    		}
    	}
		
	}
	public static void main(String[] arg){
	}
}
